<?php

class UserGroupTableSeeder extends Seeder {
    
    public function run()
    {
        DB::table('users_groups')->truncate();

        $users = Sentry::findAllUsers(); $count_id = 0;
        foreach ($users as $user) {
            $count_id ++;
            if ($count_id == 2) break;
            $matches = array();
            if (preg_match('/([a-z]+)/i', $user->email, $matches)) {
                try {
                    $group = Sentry::findGroupByName($matches[1]);
                    $user->addGroup($group);
                } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
                    echo 'Group not found';
                }

            }
        }
        
    }
    
}
